@echo off

REM Script to deploy Qt dependencies for example applications in vs2022

REM Set Qt installation path
set QT_PATH=D:\Qt\6.8.3\msvc2022_64
set WINDEPLOYQT=%QT_PATH%\bin\windeployqt.exe

REM Check if windeployqt exists
if not exist "%WINDEPLOYQT%" (
    echo Error: Cannot find windeployqt tool at %WINDEPLOYQT%
    echo Please check if Qt is installed at the specified path.
    pause
    exit /b 1
)

echo Using Qt's windeployqt tool to copy dependency DLLs for example applications...

REM Set output directories for vs2022 build
set DEBUG_DIR=D:\Nodeeditor\vs2022\bin\Debug
set RELEASE_DIR=D:\Nodeeditor\vs2022\bin\Release

REM Check if output directories exist
if not exist "%DEBUG_DIR%" (
    echo Warning: Debug directory does not exist: %DEBUG_DIR%
    echo Please build the project in Debug mode first.
)

if not exist "%RELEASE_DIR%" (
    echo Warning: Release directory does not exist: %RELEASE_DIR%
    echo Please build the project in Release mode first.
)

REM Function to deploy for a specific build type
goto DeployStart

:DeployForBuildType
set BUILD_TYPE=%~1
set OUTPUT_DIR=%~2

echo Deploying Qt dependencies for %BUILD_TYPE% version...

REM Check if output directory exists
if not exist "%OUTPUT_DIR%" (
    echo Warning: %BUILD_TYPE% directory does not exist: %OUTPUT_DIR%
    exit /b 1
)

REM Process each example executable
for %%E in (
    calculator.exe
    connection_colors.exe
    dynamic_ports.exe
    lock_nodes_and_connections.exe
    resizable_images.exe
    simple_graph_model.exe
    styles.exe
    text.exe
    vertical_layout.exe
    headless_calculator.exe
) do (
    if exist "%OUTPUT_DIR%\%%E" (
        echo Deploying for %%E...
        "%WINDEPLOYQT%" --no-translations --no-system-d3d-compiler --no-opengl-sw "%OUTPUT_DIR%\%%E"
        echo %%E %BUILD_TYPE% deployment completed!
    )
)

exit /b 0

:DeployStart
REM Deploy for Debug version
call :DeployForBuildType "Debug" "%DEBUG_DIR%"

REM Deploy for Release version
call :DeployForBuildType "Release" "%RELEASE_DIR%"

echo All deployment operations completed!
pause